﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using VipGrade;

public partial class admin_VipGrade_VipGradeRights : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("User", "B1");
        if (!IsPostBack)
        {
            int id = 0;
            try
            {
                if (Request.QueryString["id"] == null || Request.QueryString["id"] == "")
                {
                    throw new Exception("该会员等级不存在！");
                }
                else
                {
                    id = Convert.ToInt32(Request.QueryString["id"]);
                    IVipGrade Vipgrade = new RVipGrade();
                    DataTable da = Vipgrade.GetDataTable(id);
                    this.DrpManageRights.SelectedValue = da.Rows[0]["ManageRights"].ToString();
                    this.txtSupplyCount.Text = da.Rows[0]["SupplyCount"].ToString();
                    this.txtPurchaseCount.Text = da.Rows[0]["PurchaseCount"].ToString();
                    this.txtExpoCount.Text = da.Rows[0]["ExpoCount"].ToString();
                    this.txtSincereCount.Text = da.Rows[0]["SincereCount"].ToString();
                    this.txtWillCount.Text = da.Rows[0]["WillCount"].ToString();
                }
            }
            catch(Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
    }


    /// <summary>
    ///  更新提交
    /// </summary>
    protected void ButSave_Click(object sender, EventArgs e)
    {
        try
        {
            //if (Base.Common.CheckNum(this.txtServiceTime.Text.Trim()) || Base.Common.CheckNum(this.txtPrice.Text.Trim()))
            //{
            //    ShowMessage("输入的服务年限或申请费用不是数字类型<br>");
            //    return;
            //}
             int id = 0;
            if (Request.QueryString["id"] == null || Request.QueryString["id"] == "")
            {
                throw new Exception("该会员等级不存在！");
            }
            else
            {
                id = Convert.ToInt32(Request.QueryString["id"]);
                IVipGrade Vipgrade = new RVipGrade();
                TVipGrade ur = new TVipGrade();
                ur.ID = id;
                ur.ManageRights = this.DrpManageRights.SelectedValue.ToString();
                ur.SupplyCount = Convert.ToInt32(this.txtSupplyCount.Text.Trim());
                ur.PurchaseCount = Convert.ToInt32(this.txtPurchaseCount.Text.Trim());
                ur.ExpoCount = Convert.ToInt32(this.txtExpoCount.Text.Trim());
                ur.SincereCount = Convert.ToInt32(this.txtSincereCount.Text.Trim());
                ur.WillCount = Convert.ToInt32(this.txtWillCount.Text.Trim());

                int m = Vipgrade.UpdateRights(ur);
                ShowMessage("修改成功!", "VipGrade/ManageVIPGrade.aspx");
            }
        }
        catch (Exception ex)
        {
            ShowMessage("修改失败!", "VipGrade/ManageVIPGrade.aspx");
        }
    }
}
